// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CElementWithValue.
//   $Id$



#pragma once
#include "xformselementformcontrolinput2.h"
#include "CComBSTRPtrList.h"
#include <DOM2Events.h>

class CPEValueElement;

class CElementWithValue
	:public CXFormsElementFormControlInput2
	,public IDispatchImpl<IEventListener,&IID_IEventListener,&LIBID_DOM2EventsLib,2,0>
{
public:
	CElementWithValue(void);
	~CElementWithValue(void);
	virtual HRESULT put_value(BSTR bsValue);
	BEGIN_COM_MAP(CElementWithValue)
		COM_INTERFACE_ENTRY(IEventListener)
		COM_INTERFACE_ENTRY_CHAIN(CXFormsElementFormControlInput2)
	END_COM_MAP()
	STDMETHOD(Detach)();
	virtual HRESULT focus();
	
	STDMETHOD(handleEvent)(IDOMEvent *pEvt);
	virtual HRESULT handleEvent(CComBSTR &sEventName, IHTMLEventObj2 *pEventObject,VARIANT *pvResult);
	HRESULT GetInitialValueClassName(BSTR * psClassName);
	virtual HRESULT changeUI();
	HRESULT valueElementReady(CPEValueElement * pValueElement);
protected:
	virtual HRESULT ElementReady();
	virtual HRESULT DocumentReady();
	virtual HRESULT render();
	CComBSTR m_sInitialClassName;
private:
	CComPtr<IHTMLElement> m_pValueElement;
	CPEValueElement * m_pValueObject;

	HRESULT CreateValuePseudoElement(IHTMLElement * pMasterEl);
	HRESULT InsertValuePseudoElement(IHTMLElement * pEl, BSTR bsWhere);
	
	void populateEvents(void);
	void populateValueEvents();
	HRESULT attachValueEvents();
	HRESULT detachValueEvents();
	virtual HRESULT detachEvents();

	CComBSTRPtrList m_lstValueEvents;
	

};

